import request from "../utils/request"
export default{
    getAllUserList(pageNum, pageSize){
        let params = {
            pageNum: pageNum,
            pageSize: pageSize
        }
        return request.get("/user", { params }, {
            method: "get",
        })
    },
    getUserManagementSelect(){
        return request.get("/user/getUserManagementSelect",{},{
            method: "get",
        })
    },
    addUser(addUser){
        return request.post("/user/addUser",addUser,{
            method: "post",
        })
    },
    getEditUser(id){
        const  params = {
            id
        }
        return request.get("/user/getEditUser",{params},{
            method: "get",
        })
    },
    updateUser(updateUser){
        return request.put("/user",updateUser,{
            method: "put",
        })
    },
    deleteUser(id){
        let params;
        if(typeof id === "string"){
            params = {
                id:[id]
            }
        }else{  
            params = {
                id: id
            }
        }
        return request.patch("/user",params,{
            method: "patch",
        })
    },
    getSpecieUser(username,mobile, status, time, pageNum, pageSize){ 
        let params = {
            username: username,
            mobile: mobile,
            status: status,
            // 安全访问 time 数组，未选择时间时自动过滤字段
            ...(time?.[0] && { startTime: time[0] }),  // 仅当 time[0] 存在时添加 startTime
            ...(time?.[1] && { endTime: time[1] }),     // 仅当 time[1] 存在时添加 endTime
            pageNum: pageNum,
            pageSize: pageSize,
        }
        return request.get("/user/getSpecieUser",{params},{
            method: "get",
        })
    },
    getPersonalDetail(){
        return request.get("/user/getPersonalDetails",{
            method: "get",
        })
    },
    updatePersonalDetail(updatePersonalDetail){
        return request.put("/user/updatePersonalDetails",updatePersonalDetail,{
            method: "put",
        })
    },
    updatePersonPassword(newPassword, oldPassword,id){
        const params = {
            newPassword,
            oldPassword,
            id
        }
        return request.put("/user/updatePersonPassword",params,{
            method: "put",
        })
    },
    updateUserPassword(newPassword, id){
        const params = {
            newPassword,
            id
        }
        return request.put("/user/updateUserPassword",params,{
            method: "put",
        })
    },
    userLoginOut(){
        return request.post("/user/loginOut",{},{
            method: "post",
        })
    }
}